<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js"></script>
  </head>
  <body>
    <div>URL: <button class="button" onclick="fetch()">创建</button></div>
    <button class="test" onclick="test()">c测是</button>
    <input style="width: 900px; height: 40px" class="url" type="text" />
    <div>Data:</div>
    <div id="editor" style="width: 100%; height: 400px"></div>
    <script>
      const editor = ace.edit("editor");
      editor.setTheme("ace/theme/monokai"); // 设置主题为 Monokai
      editor.session.setMode("ace/mode/json"); // 设置模式为 JSON
    </script>
    <script>
      const url = document.querySelector(".url");
      const button = document.querySelector(".button");
      const test = document.querySelector(".test");
      button.onclick = () => {
        const status = editor.getSession().getAnnotations().length;
        const value = editor.getValue();
        if (!status) {
          axios
            .post("/upPathData", {
              url: url.value,
              data: JSON.parse(value),
            })
            .then(({ data }) => {
              if (data.code === 200) {
                alert(data.message);
              } else {
                alert(data.message);
              }
            });
        } else {
          alert("请检查你的json是否正确");
        }
      };
      test.onclick = () => {
        // axios
        //     .post("/api/upPathData", {
        //       url: '/qr-admin/product/edit',
        //       data:{
        //         id:1
        //       },
        //     })
        axios.get('http://47.95.201.113:8080/qr-admin/login')
      }
  </script>
  </body>
</html>
